package com.example.administrator.yuejian2.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.example.administrator.yuejian2.R;

import com.example.administrator.yuejian2.bean.ActivityBean;
import com.example.administrator.yuejian2.bean.ClubBean;
import com.example.administrator.yuejian2.viewholder.ActivityViewHolder;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.example.administrator.yuejian2.other.Url.IMAGEURL;

public class ActivityAdapter extends DelegateAdapter.Adapter{

    private Context context;
    private LayoutInflater layoutInflater;
    private List<ActivityBean> list;
    private LayoutHelper helper;
    public ActivityAdapter(Context context,LayoutHelper helper)
    {
        this.layoutInflater = LayoutInflater.from(context);
        this.helper=helper;
        this.context=context;
    }
    public void activityData(List<ActivityBean> list)
    {
        this.list=list;
        notifyDataSetChanged();
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return helper;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v=LayoutInflater.from(parent.getContext()).inflate(R.layout.acitivity_item,parent,false);
        return new ActivityViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ActivityViewHolder viewHolder=(ActivityViewHolder)holder;
        ActivityBean bean=list.get(position);
        final String id=bean.getActivity_id();
        viewHolder.activity_pic.setImageBitmap(BitmapFactory.decodeResource(context.getResources(), R.mipmap.loading));
        viewHolder.activity_name.setText(bean.getActivity_title());
        viewHolder.activity_address.setText(bean.getActivity_address());
        Picasso.with(context)
                .load(IMAGEURL+bean.getActivity_pic())
                .placeholder(R.mipmap.loading)
                .into(viewHolder.activity_pic);

    }
    @Override
    public int getItemCount() {
        if (list==null)
        {
        return 0;
    }
     else
        {
            return list.size();
        }

    }


}
